Add regexp/grapheme-string-literal rule#646
Conversation
🦋 Changeset detectedLatest commit: 331159a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Same problem as #642. |
| code: String.raw`/[\q{abc}]/v`, | ||
| errors: [ | ||
| { | ||
| message: "Use single grapheme in string literal.", |
There was a problem hiding this comment.
The error message needs to be improved. If I didn't read the docs for the rule, I would have no idea what the error message wants me to do.
Maybe we could say this: "Only single characters and graphemes are allowed inside character classes. Use regular alternatives (e.g. (?:foo|[...])) for strings instead."
There was a problem hiding this comment.
Thank you! I will use that message.
| meta: { | ||
| docs: { | ||
| description: "enforce single grapheme in string literal", | ||
| category: "Best Practices", |
There was a problem hiding this comment.
I'm not sure whether this should be a best practice. The practice this rule enforces is good, because it brings regexes into a canonical form (e.g. don't use [\q{foo|bar}], use (?:foo|bar)), but that's more of a stylistic thing IMO.
There was a problem hiding this comment.
I agree with you 👍 I will categorize it under "Stylistic Issues".
close #644